package com.hailiao.beidou.message.data.contact

import com.hailiao.beidou.message.data.db.DB
import com.hailiao.beidou.message.data.db.entity.ContactEntity

/**
 * 联系人数据仓库
 * @Author d10ng
 * @Date 2024/3/2 14:50
 */
object ContactRepository {

    private val contactDao by lazy { DB.instant.contactDao() }

    // 联系人列表
    val listFlow by lazy { contactDao.query() }

    /**
     * 模糊查询
     * @param key String
     * @return List<ContactEntity>
     */
    suspend fun search(key: String) = contactDao.susQueryBlur(key)

    /**
     * 查询特定联系人
     * @param number String
     * @return ContactEntity?
     */
    suspend fun get(number: String) = contactDao.susQuery(number)

    /**
     * 查询特定联系人Flow
     * @param number String
     * @return ContactEntity?
     */
    fun getFlow(number: String) = contactDao.query(number)

    /**
     * 更新联系人
     * @param info ContactEntity
     */
    suspend fun update(info: ContactEntity) = contactDao.update(info)

    /**
     * 插入联系人
     * @param info ContactEntity
     */
    suspend fun insert(info: ContactEntity) = contactDao.insert(info)

    /**
     * 删除联系人
     * @param info ContactEntity
     */
    suspend fun delete(info: ContactEntity) = contactDao.deleteWithChatAndMessage(info)
}